<template>
  <div v-if="visible" class="alert" :class="[`alert-${type}`, { 'is-center': center }]">
    <i v-if="showIcon" :class="iconClass"></i>
    <div class="alert-content">
      <span v-if="title" class="alert-title">{{ title }}</span>
      <p v-if="$slots.default" class="alert-description">
        <slot></slot>
      </p>
    </div>
    <button v-if="closable" class="alert-close" @click="handleClose">&times;</button>
  </div>
</template>

<script>
export default {
  name: 'FeedbackAlert',
  props: {
    title: {
      type: String,
      default: ''
    },
    type: {
      type: String,
      default: 'info',
      validator: value => ['success', 'warning', 'info', 'error'].includes(value)
    },
    closable: {
      type: Boolean,
      default: true
    },
    showIcon: {
      type: Boolean,
      default: true
    },
    center: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      visible: true
    }
  },
  computed: {
    iconClass() {
      const iconMap = {
        success: 'icon-success',
        warning: 'icon-warning',
        info: 'icon-info',
        error: 'icon-error'
      }
      return iconMap[this.type]
    }
  },
  methods: {
    handleClose() {
      this.visible = false
      this.$emit('close')
    }
  }
}
</script>

<style scoped>
.alert {
  position: relative;
  padding: 8px 16px;
  border-radius: 4px;
  margin-bottom: 10px;
  display: flex;
  align-items: flex-start;
}

.alert.is-center {
  justify-content: center;
}

.alert-content {
  flex: 1;
  margin: 0 8px;
}

.alert-title {
  font-weight: bold;
  display: block;
  margin-bottom: 5px;
}

.alert-description {
  margin: 0;
  font-size: 14px;
  line-height: 1.5;
}

.alert-close {
  position: absolute;
  top: 12px;
  right: 15px;
  padding: 0;
  background: transparent;
  border: none;
  outline: none;
  font-size: 16px;
  cursor: pointer;
  color: #999;
}

.alert-success {
  background-color: #f0f9eb;
  color: #67c23a;
}

.alert-warning {
  background-color: #fdf6ec;
  color: #e6a23c;
}

.alert-info {
  background-color: #f4f4f5;
  color: #909399;
}

.alert-error {
  background-color: #fef0f0;
  color: #f56c6c;
}

.icon-success::before {
  content: "✓";
}

.icon-warning::before {
  content: "!";
}

.icon-info::before {
  content: "i";
}

.icon-error::before {
  content: "×";
}
</style> 